package pers.brozen.anka.support.web.response;

import lombok.Data;
import lombok.ToString;

import java.io.Serial;
import java.io.Serializable;

@Data
@ToString
public class Response<T> implements Serializable {

    @Serial
    private static final long serialVersionUID = -1L;

    private int status;
    private String message;
    private T data;

    public Response(Response<T> other) {
        this(other.status, other.message);
    }

    public Response(ErrorCodes errorCode) {
        this(errorCode.code, errorCode.message);
    }

    public Response(T data) {
        this(ErrorCodes.SUCCESS.code, "", data);
    }

    public Response(Integer status, String msg) {
        this(status, msg, null);
    }

    public Response(Integer status, String msg, T data) {
        this.status = status;
        this.message = msg;
        this.data = data;
    }


    /**
     * 返回一个状态为成功的Response对象
     */
    public static <T> Response<T> ofSuccess(T data) {
        return new Response<>(data);
    }


    /**
     * 返回一个状态为成功的Response对象
     */
    public static <T> Response<T> ofSuccess() {
        return new Response<>(ErrorCodes.SUCCESS);
    }


    /**
     * 返回一个包含错误状态的Response对象
     */
    @Deprecated
    public static <T> Response<T> ofError(ErrorCodes errorCode) {
        return new Response<>(errorCode);
    }

}